package com.asia5b.a5bmall.same.fragment

import android.view.ViewGroup
import androidx.recyclerview.widget.LinearLayoutManager
import com.asia5b.a5bmall.same.adapter.OrderCouponAdapter
import com.asia5b.a5bmall.same.databinding.DialogGoodscouponBinding
import com.asia5b.a5mall.middleware.base.SimpleDialogFragment
import com.asia5b.a5mall.middleware.base.SimpleViewModel
import com.asia5b.a5mall.middleware.model.member.UserCouponModel
import kotlinx.android.synthetic.main.dialog_goodscoupon.*

/**
 * Created by zhangyuncai on 2020/3/23.
 */
class OrderCouponDF : SimpleDialogFragment<SimpleViewModel,DialogGoodscouponBinding>() {
    override val viewModelClazz: Class<SimpleViewModel>
        get() = SimpleViewModel::class.java

    override fun getDataBinding(container: ViewGroup?): DialogGoodscouponBinding {
        return DialogGoodscouponBinding.inflate(layoutInflater,container,false)
    }
    val mRecyclerView by lazy { rv_couponlist }
    val mDatas = arrayListOf<UserCouponModel>()
    val mAdapter by lazy { OrderCouponAdapter(mDatas) }

    override fun initView() {
        mRecyclerView.run {
            layoutManager = LinearLayoutManager(mActivity)
            adapter = mAdapter
        }
    }

    override fun initData() {
    }

    override fun initEvent() {
        mAdapter.setOnItemChildClickListener { adapter, view, position ->
            val item = mAdapter.getItem(position) as UserCouponModel
            mSureClick?.invoke(item)
            dismiss()
        }
    }

    override val heightPercent: Double
        get() = 0.7

}